package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {

    @Resource
    private RestTemplate restTemplate;

    public static  final String PAYMENT_URL="http://cloud-paymentConsul-service";

    @GetMapping("/consumer/payment/creat")
    public CommonResult<Payment> creat(Payment payment){

        return restTemplate.postForObject(PAYMENT_URL+"/payments",payment,CommonResult.class);

    }


    @GetMapping(value = "/consumer/payment/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") long id){
        log.info("请求地址"+PAYMENT_URL+"/payment/"+id);
        return   restTemplate.getForObject(PAYMENT_URL+"/payment/"+id,CommonResult.class);
    }




}
